<template>
	<gui-page ref="guiPage" :customHeader="true">
		<template v-slot:gHeader>
			<nav-bar-custom scanType="0" @clickLeftBack="handelSure" left-icon="left" :title="$t('materials.warehouseSelection')"></nav-bar-custom>
		</template>
		<template v-slot:gBody>
			<view class=" page-auto warehouse">
				<uni-list v-for="(item, index) in data.warehouseList" :key="index" class="warehouse-card"
					@click="select(item)">
					<uni-list-item class="warehouse-card-list" :title="item.warehouseCode"></uni-list-item>
					<radio class="warehouse-card-checkbox" value="data.id" :checked="item.id == data.id" @click="select(item)" />
				</uni-list>
			</view>
		</template>
	</gui-page>
</template>


<script setup>
import { ref, reactive, onMounted } from 'vue';
import superweiCombox from '@/components/superweiCombox';
import { navigate, navigateBack } from '@/utils/routerSkip.js'
import comboGrid from "@/components/comboGrid";
import { getIsUsePageSetPDA } from '@/api/api.js';
import tableColor from '@/hooks/tableColor.js';
import { onShow } from '@dcloudio/uni-app';
import { SELECT_WAREHOUSEID, SELECT_WAREHOUSENAME, SELECT_WAREHOUSECODE } from '@/constant/index.js'
//JS国际化引入
import { useI18n } from 'vue-i18n';
const { t } = useI18n();

const data = reactive({
	id: '',
	warehouseName: '',
	warehouseCode: '',
	warehouseList: [],
	ckeck:false
})

// 页面显示获取数据
onShow(() => {
	warehouse()
})

// 获取仓库
const warehouse = () => {
	let parmes = {
		warehouseName: data.warehouseName
	}
	getIsUsePageSetPDA(parmes).then(res => {
		if (res.status == 200) {
			data.warehouseList = res.data.rows
			data.warehouseList.unshift({
				LastModifyTime: null,
				attribute1: null,
				attribute2: null,
				attribute3: null,
				createUserName: "Super Admin",
				createUserNo: "admin",
				creationTime: "2022-09-27 16:09:23",
				erpId: null,
				forbiddenStatus: "Yes",
				id: 55,
				lastModifyTime: null,
				lastModifyUserName: null,
				lastModifyUserNo: null,
				orgId: 500,
				warehouseCode: "All",
				warehouseName: "全部仓库",
				warehouseTypeCode: "All",
				warehouseTypeName: "全部仓库",
				warehouseTypeNameBak: null,
			})
		
		//设置仓库选中
		var  selectStoreId=uni.getStorageSync(SELECT_WAREHOUSEID)
		
		if (selectStoreId!=''&&selectStoreId!=null) {	
			data.id = uni.getStorageSync(SELECT_WAREHOUSEID)
		}
		else{
			  data.id=0
		}
		}
	})
}

const select = (item) => {
	data.warehouseName = item.warehouseName
	data.warehouseCode = item.warehouseCode
	data.id = item.id
	data.ckeck=!data.ckeck
	uni.setStorageSync(SELECT_WAREHOUSECODE, data.ckeck ? item.warehouseCode : '');
	uni.setStorageSync(SELECT_WAREHOUSENAME, data.ckeck ? item.warehouseName : '');
	uni.setStorageSync(SELECT_WAREHOUSEID, data.ckeck ? item.id + '' : '');
	navigateBack()
}
</script>

<style scoped lang="scss">
.warehouse {
	display: flex;
	flex-direction: column;
	height: calc(100vh - 130rpx);
	background-color: #fff;
	margin: 20rpx;
	box-sizing: border-box;

	&-card {
		display: flex;
		flex-direction: row;

		&-list {
			height: 100%;
			width: 90%;
		}

		&-checkbox {
			flex: 1;
			margin-top: 20rpx;
			display: inline-block;
		}
	}
}
</style>